//
// Created by heqian on 17-8-11.
//

#include "Mahjong.h"
#include "../utils/Socket.h"
#include "../utils/HttpClient.h"

using namespace std;

namespace mahjong {
    void Callinterface::info(Prt<BoardInfo> &info) {

    }

    bool Callinterface::simulateClick(int x, int y) {
        return false;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////
    std::string &trim(std::string &s) {
        if (s.empty())
            return s;

        s.erase(0, s.find_first_not_of(" "));
        s.erase(s.find_last_not_of(" ") + 1);
        return s;
    }


    Mahjong::Mahjong(Prt<Callinterface> &mCall)
            : mCall(mCall) {
    }

    void Mahjong::discern(Prt<Image> img) {
        mIdentify.start(img);
        if (!mCall.isNull())
            mCall->info(mIdentify.getMBoardInfo());
    }

    EnumLogin Mahjong::tokenLogin() {
        return NONE;
    }

    EnumLogin Mahjong::login(string mobile, string pass) {
        mobile = trim(mobile);
        if (0 == mobile.size())
            return MobileError;

        if (0 == pass.size())
            return PassWordError;

        HttpClient client;
        client.setData("HttpClient", 7);
        client.post("http://192.168.19.66:8080/app/login");
        string body = client.getBodyData();

        return NONE;
    }

}